#include "Auto.h"

void Keyboard::down(int vk)
{
	sleep(300);
	INPUT inputs[1] = { 0 };
	inputs[0].type = INPUT_KEYBOARD;
	inputs[0].ki.wVk = vk;
	inputs[0].ki.wScan = 0;  // wait for modify
	inputs[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY | 0;
	inputs[0].ki.time = NULL;
	inputs[0].ki.dwExtraInfo = NULL;
	UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
}

void Keyboard::down(char vk)
{
	sleep(300);
	INPUT inputs[1] = { 0 };
	inputs[0].type = INPUT_KEYBOARD;
	inputs[0].ki.wVk = VkKeyScan(vk);
	inputs[0].ki.wScan = 0;  // wait for modify
	inputs[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY | 0;
	inputs[0].ki.time = NULL;
	inputs[0].ki.dwExtraInfo = NULL;
	UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
}

void Keyboard::up(int vk)
{
	sleep(300);
	INPUT inputs[1] = { 0 };
	inputs[0].type = INPUT_KEYBOARD;
	inputs[0].ki.wVk = vk;
	inputs[0].ki.wScan = 0;  // wait for modify
	inputs[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
	inputs[0].ki.time = NULL;
	inputs[0].ki.dwExtraInfo = NULL;
	UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
}

void Keyboard::up(char vk)
{
	sleep(300);
	INPUT inputs[1] = { 0 };
	inputs[0].type = INPUT_KEYBOARD;
	inputs[0].ki.wVk = VkKeyScan(vk);
	inputs[0].ki.wScan = 0;  // wait for modify
	inputs[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
	inputs[0].ki.time = NULL;
	inputs[0].ki.dwExtraInfo = NULL;
	UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
}

void Keyboard::press(int vk)
{
	Keyboard::down(vk);
	Keyboard::up(vk);
}
void Keyboard::press(char vk)
{
	Keyboard::down(vk);
	Keyboard::up(vk);
}